using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.HtmlControls;

namespace MessageBoardControl
{
	/// <summary>
	/// Summary description for AddGroup.
	/// </summary>
	[DefaultProperty("Text"), 
		ToolboxData("<{0}:AddGroup runat=server></{0}:AddGroup>")]
	public class DeleteGroup : Control, INamingContainer 
	{
		private string text;
	
		[Bindable(true), 
			Category("Appearance"), 
			DefaultValue("")] 
		public string Text 
		{
			get
			{
				return text;
			}

			set
			{
				text = value;
			}
		}

		private string urlAfter;
		[Bindable(true), 
		Category("Appearance"), 
		DefaultValue("")] 
		public string URLAfter 
		{
			get
			{
				return urlAfter;
			}

			set
			{
				urlAfter = value;
			}
		}

		private MessageBoard.Group _Group;
		[Bindable(true), 
		Category("Appearance"), 
		DefaultValue("")] 
		public MessageBoard.Group Group 
		{
			get
			{
				return _Group;
			}

			set
			{
				_Group = value;
			}
		}

		private MessageBoard.Language language;

		[Bindable(true), 
		Category("Appearance"), 
		DefaultValue("")] 
		public MessageBoard.Language Language 
		{
			get
			{
				return language;
			}

			set
			{
				language = value;
			}
		}

		/// <summary> 
		/// Render this control to the output parameter specified.
		/// </summary>
		/// <param name="output"> The HTML writer to write out to </param>
		//protected override void Render(HtmlTextWriter output)
		//{
		//	output.Write(Text);
		//}

		protected override void CreateChildControls() 
		{
			Button cmdYes = new Button();
			Button cmdNo = new Button();
			
			cmdYes.Text = Translate("Yes");
			cmdNo.Text = Translate("No");

			// Put the contols in a table.
			HtmlTable table = new HtmlTable();
			table.Attributes.Add("width", "100%");
			HtmlTableRow tr0 = new HtmlTableRow();
			table.Controls.Add(tr0);
			HtmlTableCell td0 = new HtmlTableCell();
			tr0.Controls.Add(td0);
			td0.Attributes.Add("class", "Forum_Title1");
			td0.InnerHtml = Translate("Are you sure you want to delete this group?");

			HtmlTableRow tr01 = new HtmlTableRow();
			table.Controls.Add(tr01);
			HtmlTableCell td01 = new HtmlTableCell();
			tr01.Controls.Add(td01);
			td01.Attributes.Add("class", "Forum_Title4");

			// Table 2
			HtmlTable table2 = new HtmlTable();
			table2.Attributes.Add("width", "100%");

			// Title
			HtmlTableRow tr1 = new HtmlTableRow();
			table2.Controls.Add(tr1);
			HtmlTableCell td11 = new HtmlTableCell();
			HtmlTableCell td12 = new HtmlTableCell();
			td11.InnerHtml = Translate("Title")+":";
			td11.Attributes.Add("class", "Forum_Text");
			td12.InnerHtml = _Group.Title;
			tr1.Controls.Add(td11);
			tr1.Controls.Add(td12);
			

			// Description
			HtmlTableRow tr2 = new HtmlTableRow();
			table2.Controls.Add(tr2);
			HtmlTableCell td21 = new HtmlTableCell();
			HtmlTableCell td22 = new HtmlTableCell();
			td21.InnerHtml = Translate("Description")+":";
			td21.Attributes.Add("width", "150");
			td21.Attributes.Add("class", "Forum_Text");
			td21.Attributes.Add("vAlign", "top");
			td22.InnerHtml = _Group.Description;
			tr2.Controls.Add(td21);
			tr2.Controls.Add(td22);


			// Button
			HtmlTableRow tr3 = new HtmlTableRow();
			table2.Controls.Add(tr3);
			HtmlTableCell td31 = new HtmlTableCell();
			HtmlTableCell td32 = new HtmlTableCell();
			td31.InnerHtml = "";
			td32.Controls.Add(cmdYes);
			td32.Controls.Add(cmdNo);
			tr3.Controls.Add(td31);
			tr3.Controls.Add(td32);

			td01.Controls.Add(table2);

			HtmlTable tableOut = new HtmlTable();
			HtmlTableRow trOut = new HtmlTableRow();
			HtmlTableCell tdOut = new HtmlTableCell();
			tableOut.BgColor = "#000000";
			tableOut.Attributes.Add("width", "100%");
			tableOut.CellPadding = 0;
			tableOut.CellSpacing = 0;
			table.CellSpacing = 1;
			tdOut.Controls.Add(table);
			trOut.Controls.Add(tdOut);
			tableOut.Controls.Add(trOut);
			Controls.Add(tableOut);

			cmdYes.Click += new EventHandler(cmdYes_Click);
			cmdNo.Click += new EventHandler(cmdNo_Click);
                  
		}

		public void cmdYes_Click(Object sender, EventArgs e)
		{
			_Group.Delete();
			this.EnsureChildControls();
			this.Page.Response.Redirect(urlAfter);
		}

		public void cmdNo_Click(Object sender, EventArgs e)
		{
			this.EnsureChildControls();
			this.Page.Response.Redirect(urlAfter);
		}

		private MessageBoard.CustomControl customControl = MessageBoard.CustomControl.Get("DeleteGroup");

		private string Translate(string word)
		{
			return MessageBoard.Translation.Get(customControl, word, Language).Equal;
		}

	}
}
